package com.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/cookieServlet7")
public class CookieServlet7 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("执行了CookieServlet7...");

        //方式一
        //创建cookie对象
        Cookie c = new Cookie("name", "rose");

        //设置cookie的生命时长
        //c.setMaxAge(60);

        //设置cookie携带范围
        //c.setPath("/java-web");//默认设置
        c.setPath("/java-web/cookieServlet6");

        //添加cookie信息, 设置cookie的响应信息
        response.addCookie(c);

        System.out.println("添加完成...");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
